﻿// --------------------------------
// <copyright file="MethodDefinitionTest.cs" company="TRONSoft">
//     Copyright (c) TRONSoft.
// </copyright>
// <license>
//   This source code is subject to terms and conditions of the Microsoft
//   Public License. A copy of the license can be found in the License.html
//   file at the root of this distribution. If you cannot locate the
//   Microsoft Public License, please send an email to dlr@microsoft.com.
//   By using this source code in any fashion, you are agreeing to be bound 
//   by the terms of the Microsoft Public License. You must not remove this
//   notice, or any other, from this software.
// </license>
// <author>Tron</author>
// ---------------------------------

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tronsoft.Actucal.CalculationEngineCreator.Test
{    
    /// <summary>
    ///This is a test class for MethodDefinitionTest and is intended
    ///to contain all MethodDefinitionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MethodDefinitionTest
    {
        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for Signature
        ///</summary>
        [TestMethod()]
        public void Signature_Test()
        {
            string name = "name";
            MethodSignature signature = new MethodSignature();
            signature.AddParameter("p1", typeof (int));
            signature.ReturnValue = typeof (int);
            string body = 
@"int count = 0;
count += 1;
return count;";

            MethodDefinition target = new MethodDefinition(name, signature, body);
            MethodSignature actual = target.Signature;
            Assert.AreEqual(signature, actual);
        }

        /// <summary>
        ///A test for Name
        ///</summary>
        [TestMethod()]
        public void Name_Test()
        {
            string name = "method1";
            MethodSignature signature = new MethodSignature();
            signature.AddParameter("p1", typeof(int));
            signature.ReturnValue = typeof(int);
            string body =
@"int count = 0;
count += 1;
return count;";

            MethodDefinition target = new MethodDefinition(name, signature, body);
            string actual = target.Name;
            Assert.AreEqual(name, target.Name);
        }

        /// <summary>
        ///A test for Body
        ///</summary>
        [TestMethod()]
        public void Body_Test()
        {
            string name = "method1";
            MethodSignature signature = new MethodSignature();
            signature.AddParameter("p1", typeof(int));
            signature.ReturnValue = typeof(int);
            string body =
@"int count = 0;
count += 1;
return count;";

            MethodDefinition target = new MethodDefinition(name, signature, body);
            string actual = target.Name;
            Assert.AreEqual(body, target.Body);
        }

        /// <summary>
        ///A test for MethodDefinition Constructor
        ///</summary>
        [TestMethod()]
        public void MethodDefinition_Constructor_Test()
        {
            string name = "method1";
            MethodSignature signature = new MethodSignature();
            signature.AddParameter("p1", typeof(int));
            signature.ReturnValue = typeof(int);
            string body =
@"int count = 0;
count += 1;
return count;";

            MethodDefinition target = new MethodDefinition(name, signature, body);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MethodDefinition_Constructor_Should_Not_Accept_Name_That_Is_Null()
        {
            new MethodDefinition(null, new MethodSignature(), "return 1;");
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MethodDefinition_Constructor_Should_Not_Accept_Name_That_Is_Empty()
        {
            new MethodDefinition("", new MethodSignature(), "return 1;");
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MethodDefinition_Constructor_Should_Not_Accept_Body_That_is_Null()
        {
            new MethodDefinition("method1", new MethodSignature(), null);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MethodDefinition_Constructor_Should_Not_Accept_Body_That_is_Empty()
        {
            new MethodDefinition("method1", new MethodSignature(), "");
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MethodDefinition_Constructor_Should_Not_Accept_Signature_That_is_Null()
        {
            new MethodDefinition("method1", null, "return 1;");
        }
    }
}
